﻿@model IEnumerable<BootyBay.Models.View_Application>

@{
    var searchWord = ViewBag.SearchWord;
}

<table>
    <tr>
        <th>Alias</th>
        <th>Created on</th>
        @*<th>Progress</th>*@
        <th>Category</th>
        <th>Is in Public Store</th>
        <th>Is Recommended</th>
        <th>Action</th>
    </tr>
    @if (Model.Count() == 0)
    {
        <tr>
            <td colspan="5">
                No data.
            </td>
        </tr>
    }
    else
    {
        foreach (var item in Model)
        {
            <tr onclick="">
                <td>@Html.ActionLink(item.ApplicationName, "ApplicationInfo", new { id = item.Id }) </td>
                <td>@item.CreationDate.ToShortDateString()</td>
                @*<td>@(String.IsNullOrEmpty(item.PackageLocationUrl) ? "Not submitted" : "Submitted") <br /></td>
                    <td></td>*@                
                <td>@item.CategoryText</td>
                <td>@item.IsPublicApp</td>
                <td>@item.IsRecommended</td>
                <td>
                    @{
            var recommended = item.IsRecommended ? "Un-Recommend" : "Recommend";
                    }

                    @Ajax.ActionLink(recommended, "RecommendApp", new { id = item.Id, name = searchWord }, new AjaxOptions { HttpMethod = "POST", InsertionMode = InsertionMode.Replace, UpdateTargetId = "packageListContent", OnBegin = "beginSubmit($(this))" }) |
                    @Ajax.ActionLink("Delete", "RemoveApp", new { id = item.Id, name = searchWord }, new AjaxOptions { HttpMethod = "POST", InsertionMode = InsertionMode.Replace, UpdateTargetId = "packageListContent", Confirm = "Sure to delete this application?", OnBegin = "beginSubmit($(this))" })
                </td>
            </tr>
        }
    }
</table>
<script type="text/javascript">
    function beginSubmit(a) {
        a.hide();
        $("<span>processing...</span>").insertAfter(a);
    }
</script>